package org.smr.ministore.micro.service;

import java.util.List;

import org.blade.dao.base.BaseMapper;
import org.blade.service.base.AbstractService;
import org.blade.utils.IdGenUtils;
import org.smr.ministore.dao.RouteMapper;
import org.smr.ministore.entities.Route;
import org.smr.ministore.service.RouteService;

import org.blade.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class RouteMicroService extends AbstractService<String, Route> implements RouteService {

	@Autowired
	private RouteMapper mapper;

    public RouteMicroService(RouteMapper mapper) {
        super(mapper);
    }

    @ResponseBody
	@RequestMapping(method = RequestMethod.POST, value = "/Route/batchSave")
	public int batchSave(@RequestBody List<Route> entities) {
    	return mapper.batchInsert(entities);
    }

    @Override
    public int batchModify(List<Route> entities) {
        return 0;
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.PUT, value = "/Route/save")
    public int save(@RequestBody Route entity) {
    	return mapper.insert(entity);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.PATCH, value = "/Route/updateById")
    public int updateById(@RequestBody Route id) {
   	 	return mapper.updateById(id);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/Route/queryById/{id}")
    public Route queryById( @PathVariable("id")String id ) {
    	return (Route) mapper.selectById(id);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.DELETE, value = "/Route/deleteById/{id}")
    public int deleteById( @PathVariable("id")String id ) {
        return mapper.deleteById(id);
    }

    @Override
    public int deleteByIdLogical(Long id) {
        return 0;
    }

    @ResponseBody
    @RequestMapping( method = RequestMethod.POST, value = "/Route/paginate/{pageSize}/{pageNum}")
    public Pager<Route> paginate(@RequestBody Route entity, @PathVariable("pageSize")Long pageSize, @PathVariable("pageNum")Long pageNum ) {
        Pager<Route> pager = new Pager(pageSize, pageNum);
        List<Route> list = this.mapper.pagination( entity, pager );
        pager.setEntities(list);
        return pager;
    }


    @Override
    public String getId() {
        return IdGenUtils.getGUID();
    }
}
